<?php

/*
Process Edit Shop (admin_edit_shop.pro.php)
*/

$rank_check = "7";
include "../global.inc.php";

$check = fetch("SELECT id FROM official_shops2 WHERE shop_name = '$add_shop_name' AND game = '$game'");

if ($use_shopkeeper == 1)
{
	$directoryName = 	"$rootPath/images/user_images/opg_$game";
	if (!file_exists($directoryName)) { mkdir($directoryName, 0777); }
	
	$directoryName2 = 	"$rootPath/images/user_images/opg_$game/shopkeepers";
	if (!file_exists($directoryName2)) { mkdir($directoryName2, 0777); }
	
	if ($HTTP_POST_FILES['keeperImage']['size'] >= 32000)
	{
		die(header(error("admin_add_shop.php?game=$game", "Your image must be under 32,000 	bytes (or 32kb)")));
	}
	
	if (!eregi("image/", $HTTP_POST_FILES['keeperImage']['type']))
	{
		die(header(error("admin_add_shop.php?game=$game", "You should only use .gif, .jpg, 	and .jpeg files for images. Please convert the image to one of these file types.")));
	}
}

if (!$check[id])
{
	die(header(error("admin_edit_shop.php?game=$game", "There is no shop with that name.")));
}
else
{
	mysql_query("UPDATE official_shops2 SET shop_name = '$add_shop_name' WHERE game = '$game' AND id = '$edit'");
	mysql_query("UPDATE official_shops2 SET shop_keeper = '$add_keeper_name' WHERE game = '$game' AND id = '$edit'");
	mysql_query("UPDATE official_shops2 SET shop_greeting = '$add_shop_greeting' WHERE game = '$game' AND id = '$edit'");
	mysql_query("UPDATE official_shops2 SET premium_only = '$premium_only' WHERE game = '$game' AND id = '$edit'");
	mysql_query("UPDATE official_shops2 SET haggle = '$haggling' WHERE game = '$game' AND id = '$edit'");
	mysql_query("UPDATE official_shops2 SET shop_keeper_attitude = '$keeper_att' WHERE game = '$game' AND id = '$edit'");
	
	$file = $HTTP_POST_FILES['keeperImage']['tmp_name'];
	$dest = "$rootPath/images/user_images/opg_$game/shopkeepers/keeper_$check[id].gif";
	
	copy($file, "$dest");
	
	header("Location: admin_edit_shop.php?game=$game&error=The+shop+$add_shop_name+has+been+edited!");
}

?>
